package com.xy.biz.fd.service.impl;

import com.xy.biz.fd.client.RepositoryEventBusClient;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;

/**
 * @author Greekn Zhang
 * @date 2021/7/5 10:29
 * @description
 */
@Service
public class RepositoryEventBus implements RepositoryEventBusClient {
    private List<Consumer<Long>> repositoryHandlerList = new CopyOnWriteArrayList<>();
    private List<Consumer<Long>> repositoryQRHandlerList = new CopyOnWriteArrayList<>();

    public void addRepositoryHandler(Consumer<Long> handler) {
        repositoryHandlerList.add(handler);
    }
    public void addRepositoryQRHandler(Consumer<Long> handler) {
        repositoryQRHandlerList.add(handler);
    }

    @Override
    public void firerRepositoryHandler(Long documentId) {
        repositoryHandlerList.forEach(e -> e.accept(documentId));
    }

    @Override
    public void firerRepositoryQRHandler(Long documentId) {
        repositoryQRHandlerList.forEach(e -> e.accept(documentId));
    }
}
